<template>
  <el-dialog
    :title="option.title"
    :visible.sync="option.isShow"
    width="70%"
    :close-on-click-modal="false"
    @open="openDialog"
    @close="closeDialog('ruleForm')"
  >
    <el-row :gutter="10">
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-col :span="24">
          <el-form-item label="任务ID" prop="TASKID">
            <el-input v-model="ruleForm.TASKID" size="small" disabled placeholder="请输入任务ID"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="申诉原因" prop="APPEALCAUSE">
            <el-input v-model="ruleForm.APPEALCAUSE" type="textarea" placeholder="请输入申诉原因"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item>
            <el-button type="primary" size="mini" @click="submitForm('ruleForm')">保存</el-button>
            <el-button @click="resetForm('ruleForm')" size="mini">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </el-dialog>
</template>

<script>
import request from "@/common/utils/requestQC";
import getGlobalParams from "@/common/utils/getGlobalParams";
import scoreappeal from "@/message/QCManage/QCSummary/scoreappeal";

export default {
  props: {
    option: Object
  },
  computed: {
    isShow: {
      get: function() {
        return this.option.isShow;
      },
      set: function(newValue) {
        this.option.isShow = newValue;
      }
    }
  },
  mounted() {},
  data() {
    return {
      isInputOption: [
        { key: "Y", label: "必输" },
        { key: "N", label: "非必输" }
      ],
      ruleForm: {
        TASKID: "",
        APPEALCAUSE: ""
      },
      // rules: {
      //   CHANNELTYPE: [{
      //     required: true,
      //     message: '请选择渠道',
      //     trigger: 'change'
      //   }],
      //   SCORETEMPLATEID: [{
      //     required: true,
      //     message: '请输入模板编号',
      //     trigger: 'change'
      //   }]

      // },
      loading: false
    };
  },
  created() {},
  methods: {
    //选择数据库列的时候触发
    // changeDBCOL(){
    //   this.ruleForm.COLNAME = ''
    //   this.ruleForm.DATALEN = ''
    //   this.ruleForm.DATAMUST = ''
    //   this.ruleForm.COLNAME = this.findName(this.option.DBCOLOption)
    //   this.ruleForm.DATALEN = this.findName(this.option.lengthOption)
    //   this.ruleForm.DATAMUST = this.findName(this.option.inputOption)
    // },

    findName(arr) {
      let data = arr.filter(item => {
        return item.FIELDKEY == this.ruleForm.DBCOL;
      });
      return data[0].FIELDVALUE;
    },
    openDialog() {
      if (this.$refs["ruleForm"] != undefined) {
        this.$refs["ruleForm"].clearValidate();
      }

      this.ruleForm = JSON.parse(JSON.stringify(this.option.row));
    },
    closeDialog(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].clearValidate();
      }
      // this.$refs[formName].clearValidate();
      this.$refs[formName].resetFields();
    },
    //保存
    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          let resBody;
          resBody = new scoreappeal();
          resBody.data.TASKID = this.ruleForm.TASKID;
          resBody.data.APPEALCAUSE = this.ruleForm.APPEALCAUSE;
          let response = await request(resBody);
          if (response.SYS_HEAD.ReturnCode == "000000") {
            this.$message({
              type: "success",
              message: "申诉成功！"
            });

            this.isShow = false;
            this.$emit('reload');
          } else {
            this.$message({
              type: "error",
              message:
                "请求失败，错误码:" +
                response.SYS_HEAD.ReturnCode +
                "，错误信息：" +
                response.SYS_HEAD.ReturnMessage
            });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].clearValidate();
        this.$refs[formName].resetFields();
      }
    }
  }
};
</script>

<style scoped>
</style>
